package com.imagecollector.common.exception;

import com.imagecollector.common.enums.CodeEnum;
import lombok.Getter;

/**
 * @Author: wrf
 * @Date: 2024/6/25 13:36
 * @Description: 基类异常类
 */
@Getter
public class BaseException extends RuntimeException{

    private Integer code;

    private String msg;

    public BaseException() {
        this.code = CodeEnum.FAIL.getCode();
    }

    public BaseException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public BaseException(CodeEnum codeEnum) {
        super(codeEnum.getMsg());
        this.code = codeEnum.getCode();
        this.msg = codeEnum.getMsg();
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
        this.code = CodeEnum.FAIL.getCode();
    }

    public BaseException code(Integer code){
        this.code = code;
        return this;
    }

    public BaseException msg(String msg){
        this.msg = msg;
        return this;
    }
}
